18 #ifndef SENSOR_FUSION_TYPES_H 19 #define SENSOR_FUSION_TYPES_H 28 #include "issdk_hal.h" 38 typedef unsigned char byte;
81 #define PI 3.141592654F 82 #define PIOVER2 1.570796327F
83 #define FPIOVER180 0.01745329251994F
84 #define F180OVERPI 57.2957795130823F
85 #define F180OVERPISQ 3282.8063500117F
86 #define ONETHIRD 0.33333333F
87 #define ONESIXTH 0.166666667F
88 #define ONESIXTEENTH 0.0625F
89 #define ONEOVER12 0.083333333F
90 #define ONEOVER48 0.02083333333F
91 #define ONEOVER120 0.0083333333F
92 #define ONEOVER3840 0.0002604166667F
93 #define ONEOVERSQRT2 0.707106781F
94 #define SQRT15OVER4 0.968245837F
95 #define GTOMSEC2 9.80665
126 uint16_t read_loop_counter
138 #define SPI_ADDR 0x00 // Use SPI_ADDR as the address parameter to the installSensor function for SPI-based sensors. 374 float fQwCT6x3[6][3];
408 float fQwCT9x6[9][6];
511 #if F_6DOF_GB_BASIC // 6DOF accel and mag eCompass: (accel + mag) 517 #if F_9DOF_GBY_KALMAN 563 uint16_t numElements,
589 uint16_t maxFifoSize,
617 #endif // SENSOR_FUSION_TYPES_H Quaternion derived from 3-axis accel + 3 axis mag (eCompass)
readSensors_t readSensors
float fLPThe
low pass pitch (deg)
Quaternion fq
orientation quaternion
float flpf
low pass filter coefficient
Quaternion fqPl
a posteriori orientation quaternion
int32_t systick
systick timer
runFusion_t * runFusion
run the fusion routines
void() updateStatus_t(struct SensorFusionGlobals *sfg)
The PressureSensor structure stores raw and processed measurements for an altimeter.
float fcosDeltaPl
cos(fDeltaPl)
void addToFifo(union FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
addToFifo is called from within sensor driver read functions
float fAlphaQwbOver6
(PI / 180 * fdeltat) * Qwb / 6
void() ssSetStatus_t(struct StatusSubsystem *pStatus, fusion_status_t status)
accelerometer measurement buffer
#define ACCEL_FIFO_SIZE
FXOS8700 (accel), MMA8652, FXLS8952 all have 32 element FIFO.
installSensor_t * installSensor
function for installing a new sensor into t
uint32_t iFlags
a bit-field of sensors and algorithms used
void conditionSensorReadings(SensorFusionGlobals *sfg)
int8_t() initializeSensor_t(struct PhysicalSensor *sensor, struct SensorFusionGlobals *sfg)
struct StatusSubsystem * pStatusSubsystem
Quaternion derived from 3-axis gyro only (rotation)
void() ssUpdateStatus_t(struct StatusSubsystem *pStatus)
bool isEnabled
true if the device is sampling
float fMaxGyroOffsetChange
maximum permissible gyro offset change per iteration (deg/s)
int32_t systick_Spare
systick counter for counts spare waiting for timing interrupt
These are the state definitions for the status subsystem.
float fAlphaSqQvYQwbOver12
(PI / 180 * fdeltat)^2 * (QvY + Qwb) / 12
Receiving commands over wireless interface (momentary)
The SV_1DOF_P_BASIC structure contains state information for a pressure sensor/altimeter.
This structure defines the spi slave command format.
float fCountsPeruT
counts per uT
The MagSensor structure stores raw and processed measurements for a 3-axis magnetic sensor...
Quaternion derived from 3-axis accel (tilt)
uint8_t data[FXLS8962_DATA_SIZE]
Recoverable FAULT = something went wrong, but we can keep going.
void ApplyMagHAL(struct MagSensor *Mag)
Apply the magnetometer Hardware Abstraction Layer.
Initializing sensors and algorithms.
An instance of PhysicalSensor structure type should be allocated for each physical sensors (combo dev...
float fDeltaPl
a posteriori inclination angle from Kalman filter (deg)
spiSlaveSpecificParams_t slaveParams
SPI specific parameters. Not used for I2C.
uint8_t iFIFOCount
number of measurements read from FIFO
int32_t systick_I2C
systick counter to benchmark I2C reads
uint16_t schedule
Parameter to control sensor sampling rate.
bool isEnabled
true if the device is sampling
uint16_t addr
I2C address if applicable.
float fRhoPl
compass (deg)
SV_6DOF_GY_KALMAN is the 6DOF Kalman filter accelerometer and gyroscope state vector structure...
Non-recoverable FAULT = something went very wrong.
Lower level magnetic calibration interface.
int16_t iCountsPerDegPerSec
counts per deg/s
This is the 3DOF basic magnetometer state vector structure/.
float fAlphaSqOver4
(PI / 180 * fdeltat)^2 / 4
int8_t() installSensor_t(struct SensorFusionGlobals *sfg, struct PhysicalSensor *sensor, uint16_t addr, uint16_t schedule, void *bus_driver, registerDeviceInfo_t *busInfo, initializeSensor_t *initialize, readSensor_t *read)
The register_io_spi.h file declares low-level interface functions for reading and writing sensor regi...
Receiving commands over wired interface (momentary)
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...
int32_t systick
systick timer;
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.
void() clearFIFOs_t(struct SensorFusionGlobals *sfg)
int8_t resetflag
flag to request re-initialization on next pass
setStatus_t * setStatus
change status indicator immediately
uint8_t iWhoAmI
sensor whoami
int8_t resetflag
flag to request re-initialization on next pass
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
float fLPDelta
low pass filtered inclination angle (deg)
float fChi
tilt from vertical (deg)
float fMaxGyroOffsetChange
maximum permissible gyro offset change per iteration (deg/s)
float fAlphaOver2
PI / 180 * fdeltat / 2.
conditionSensorReadings_t * conditionSensorReadings
preprocessing step for sensor fusion
void() runFusion_t(struct SensorFusionGlobals *sfg)
float fLPRho
low pass compass (deg)
Quaternion fLPq
low pass filtered orientation quaternion
void initSensorFusionGlobals(SensorFusionGlobals *sfg, struct StatusSubsystem *pStatusSubsystem, struct ControlSubsystem *pControlSubsystem)
utility function to insert default values in the top level structure
SV_6DOF_GB_BASIC is the 6DOF basic accelerometer and magnetometer state vector structure.
This structure defines the device specific info required by register I/O.
int32_t loopcounter
counter incrementing each iteration of sensor fusion (typically 25Hz)
void clearFIFOs(SensorFusionGlobals *sfg)
Function to clear FIFO at the end of each fusion computation.
float fDegPerSecPerCount
deg/s per count
float fCountsPerg
counts per g
int8_t resetflag
flag to request re-initialization on next pass
int32_t systick
systick timer
Quaternion derived from 3-axis mag only (auto compass algorithm)
Functions to convert between various orientation representations.
float fuTPerCount
uT per count
applyPerturbation_t ApplyPerturbation
ApplyPerturbation is a reverse unit-step test function.
enum quaternion quaternion_type
the quaternion type to be transmitted
float fLPRho
low pass compass (deg)
Quaternion fLPq
low pass filtered orientation quaternion
void() setStatus_t(struct SensorFusionGlobals *sfg, fusion_status_t status)
int8_t resetflag
flag to request re-initialization on next pass
quaternion
the quaternion type to be transmitted
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
float fAlphaQwbOver6
(PI / 180 * fdeltat) * Qwb / 6
uint8_t iWhoAmI
sensor whoami
int16_t iCountsPerg
counts per g
readSensors_t * readSensors
read all physical sensors
float fT
most recent unaveraged temperature (C)
int16_t iCountsPeruT
counts per uT
float fLPChi
low pass tilt from vertical (deg)
Quaternion fLPq
low pass filtered orientation quaternion
int32_t iP
most recent unaveraged pressure (counts)
struct PhysicalSensor * pSensors
a linked list of physical sensors
float fmPerCount
meters per count
float fLPT
low pass filtered temperature (C)
uint8_t iFIFOCount
number of measurements read from FIFO
uint8_t iFIFOCount
number of measurements read from FIFO
float fChi
tilt from vertical (deg)
The top level fusion structure.
int8_t resetflag
flag to request re-initialization on next pass
Quaternion derived from 3-axis accel + 3-axis gyro (gaming)
float fH
most recent unaveraged height (m)
updateStatus_t * updateStatus
status=next status
Quaternion derived from full 9-axis sensor fusion.
struct PhysicalSensor * next
pointer to next sensor in this linked list
float fdeltat
fusion filter sampling interval (s)
int8_t iFirstAccelMagLock
denotes that 9DOF orientation has locked to 6DOF eCompass
float fLPChi
low pass tilt from vertical (deg)
void() initializeFusionEngine_t(struct SensorFusionGlobals *sfg)
float fdeltat
fusion time interval (s)
int32_t systick
systick timer
float fdeltat
fusion time interval (s)
initializeFusionEngine_t initializeFusionEngine
float fLPThe
low pass pitch (deg)
float fLPPhi
low pass roll (deg)
Matrix manipulation functions.
float flpf
low pass filter coefficient
quaternion structure definition
struct SensorFusionGlobals SensorFusionGlobals
The top level fusion structure.
initializeFusionEngine_t * initializeFusionEngine
set sensor fusion structures to initial values
uint8_t iWhoAmI
sensor whoami
he ControlSubsystem encapsulates command and data streaming functions.
void conditionSample(int16_t sample[3])
conditionSample ensures that we never encounter the maximum negative two's complement value for a 16-...
float fgdeltat
g (m/s2) * fdeltat
float fLPH
low pass filtered height (m)
readSensor_t * read
pointer to function to read sensor using the supplied drivers
void() applyPerturbation_t(struct SensorFusionGlobals *sfg)
float fsinDeltaPl
sin(fDeltaPl)
initializeSensor_t * initialize
pointer to function to initialize sensor using the supplied drivers
float fdeltat
fusion time interval (s)
float fQv
measurement noise covariance matrix leading diagonal
float fLPThe
low pass pitch (deg)
#define MAG_FIFO_SIZE
FXOS8700 (mag), MAG3110 have no FIFO so equivalent to 1 element FIFO.
float fLPRho
low pass compass (deg)
struct SV_COMMON * SV_ptr
int32_t systick
systick timer;
float fLPPsi
low pass yaw (deg)
float flpf
low pass filter coefficient
Quaternion fq
unfiltered orientation quaternion
float fLPPsi
low pass yaw (deg)
float fLPPhi
low pass roll (deg)
The AccelSensor structure stores raw and processed measurements for a 3-axis accelerometer.
uint8_t iWhoAmI
sensor whoami
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
int8_t() readSensor_t(struct PhysicalSensor *sensor, struct SensorFusionGlobals *sfg)
int8_t resetflag
flag to request re-initialization on next pass
int8_t() readSensors_t(struct SensorFusionGlobals *sfg, uint16_t read_loop_counter)
Implements accelerometer calibration routines.
precision accelerometer calibration structure
void ApplyAccelHAL(struct AccelSensor *Accel)
Apply the accelerometer Hardware Abstraction Layer.
float fAlphaSqQvYQwbOver12
(PI / 180 * fdeltat)^2 * (QvY + Qwb) / 12
registerDeviceInfo_t deviceInfo
I2C device context.
volatile uint8_t iPerturbation
test perturbation to be applied
float fdeltat
fusion time interval (s)
int16_t iT
most recent unaveraged temperature (counts)
float fAlphaSqOver4
(PI / 180 * fdeltat)^2 / 4
int32_t systick
systick timer;
float fdeltat
sensor fusion interval (s)
installSensor_t installSensor
float fLPChi
low pass tilt from vertical (deg)
Running in reduced power mode.
Quaternion fq
unfiltered orientation quaternion
float fLPPsi
low pass yaw (deg)
float fLPPhi
low pass roll (deg)
int32_t systick
systick timer
void zeroArray(struct StatusSubsystem *pStatus, void *data, uint16_t size, uint16_t numElements, uint8_t check)
updateStatus_t * testStatus
increment to next enumerated status value (test only)
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.
float flpf
low pass filter coefficient
Quaternion fq
unfiltered orientation quaternion
This is the 3DOF basic accelerometer state vector structure.
Quaternion fqPl
a posteriori orientation quaternion
void() conditionSensorReadings_t(struct SensorFusionGlobals *sfg)
void ApplyGyroHAL(struct GyroSensor *Gyro)
Apply the gyroscope Hardware Abstraction Layer.
float fRhoPl
compass (deg)
int32_t iH
most recent unaveraged height (counts)
bool isEnabled
true if the device is sampling
int8_t resetflag
flag to request re-initialization on next pass
The GyroSensor structure stores raw and processed measurements for a 3-axis gyroscope.
float fDelta
unfiltered inclination angle (deg)
float fChiPl
tilt from vertical (deg)
float fChiPl
tilt from vertical (deg)
float fAlphaOver2
PI / 180 * fdeltat / 2.
fusion_status_t
Application-specific serial communications system.
float fdeltat
sensor fusion interval (s)
bool isEnabled
true if the device is sampling
applyPerturbation_t * applyPerturbation
apply step function for testing purposes
Quaternion fq
unfiltered orientation quaternion
float fCPerCount
degrees Celsius per count
float fgPerCount
g per count
int32_t systick
systick timer
#define GYRO_FIFO_SIZE
FXAX21000, FXAS21002 have 32 element FIFO.
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.
registerDeviceInfo_t * busInfo
information required for bus power management
SV_9DOF_GBY_KALMAN is the 9DOF Kalman filter accelerometer, magnetometer and gyroscope state vector s...
Magnetic Calibration Structure.
setStatus_t * queueStatus
queue status change for next regular interval
SV_3DOF_Y_BASIC structure is the 3DOF basic gyroscope state vector structure.
struct ControlSubsystem * pControlSubsystem
clearFIFOs_t * clearFIFOs
clear sensor FIFOs
StatusSubsystem() provides an object-like interface for communicating status to the user...